
<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <title>登录</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="static/login/css/font-awesome.css">
    <link rel="stylesheet" type="text/css" href="static/login/css/util.css">
    <link rel="stylesheet" type="text/css" href="static/login/css/main.css">
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script src="https://cdn.bootcss.com/reqwest/2.0.5/reqwest.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js"
            integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous">
    </script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css"
          integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>
<body>
<div id="app">
    <div class="limiter">
        <div class="container-login100">
            <div class="wrap-login100">
                <div class="login100-form-title" style="background-image: url(static/login/image/bg-01.jpg);">
                    <span class="login100-form-title-1" v-if="type==='0'">教师登录</span>
                    <span class="login100-form-title-1" v-else>学生登录</span>
                </div>
<!--                method="post" action="http://localhost:8080/SPMS/loginServlet"-->
                <div class="login100-form validate-form" >
                    <div class="wrap-input100 validate-input m-b-26" data-validate="账号不能为空">
                        <span class="label-input100">账号</span>
                        <input class="input100" type="text" name="id" placeholder="请输入账号" v-model="id">
                        <span class="focus-input100"></span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-18" data-validate="密码不能为空">
                        <span class="label-input100">密码</span>
                        <input class="input100" type="password" name="password" v-model="password">
                        <span class="focus-input100"></span>
                    </div>

                    <div class="flex-sb-m w-full p-b-30">
                        <div class="contact100-form-checkbox">
                            <input class="input-checkbox100" id="ckb1" type="checkbox" name="remember-me">
                            <label class="label-checkbox100" for="ckb1">记住我</label>
                        </div>

                        <div>
                            <a href="javascript:" class="txt1">忘记密码？</a>
                        </div>
                    </div>
                    <div class="container-login100-form-btn" @click="login">
                        <button class="login100-form-btn">登 录</button>
                    </div>
                    <div class="row">
                        <div class="col-md-6" @click="type='0'">
                            <span class="glyphicon glyphicon-briefcase" aria-hidden="true">教师登录</span>
                        </div>
                        <div class="col-md-6" @click="type='1'">
                            <span class="glyphicon glyphicon-education" aria-hidden="true">学生登录</span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            id: "",
            password: "",
            data: {},
            type: '1'
        },
        methods: {

            login: function () {
                let self = this;
                let servletURL = "StudentLoginServlet";
                let indexURL = "StudentIndex.html";
                if(this.type === '0') {
                    servletURL = "TeacherLoginServlet";
                    indexURL = "TeacherIndex.html";
                }
                reqwest({
                    url: servletURL
                    , method: 'post'
                    , data: {
                        id: self.id,
                        password: self.password
                    }
                    , error: function (err) {
                        alert("用户名或密码错误");
                        // window.location.href = "http://localhost:8080/SPMS/login.html";
                    }
                    , success: function (data) {
                        if(data['code']===200) {
                            alert("登录成功");
                            self.data = data;
                            window.location.href = indexURL;
                        } else {
                            alert(data["msg"])
                        }
                    }
                })
            }
        }
    })
</script>
<script src="static/depend/js/jquery-3.2.1.min.js"></script>
<script src="static/login/js/main.js"></script>
</body>

</html>